package com.haoyun.mirage.auth.vo;

import com.google.common.collect.Lists;
import com.haoyun.common.constant.CommonConstant;
import com.haoyun.common.constant.SecurityConstants;
import com.xiaoleilu.hutool.collection.CollectionUtil;
import com.xiaoleilu.hutool.util.StrUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * Created by twg on 2018/6/3.
 */
@Data
public class UserVO implements Serializable {

    private static final long serialVersionUID = 6151491293299693607L;

    private Long id;
    private String userName;
    private String realName;
    private Long compId;//公司ID
    private Integer userLevel;//用户级别
    private String userPassword;
    private String salt;
    private Integer isEnabled;

    private Set<RoleVO> rolesSet;

    /**
     * 角色编号集合
     */
    private String[] roles;

    /**
     * 权限标识集合
     */
    private String[] permissions;

    public String[] getRoles() {
        List<String> roleCodes = Lists.newArrayList();
        if (CollectionUtil.isNotEmpty(rolesSet)) {
            for (RoleVO roleVO : rolesSet) {
                if (!StrUtil.equals(SecurityConstants.BASE_ROLE, roleVO.getRoleCode())) {
                    roleCodes.add(roleVO.getRoleCode());
                }
            }
        }
        return roleCodes.toArray(new String[roleCodes.size()]);
    }

    public boolean isNonExpired(){
        return !CommonConstant.STATUS_EXPIRE.equals(isEnabled) ? true : false;
    }

    public boolean isNonLocked(){
        return !CommonConstant.STATUS_LOCK.equals(isEnabled) ? true : false;
    }

    public boolean isPasswordNonExpired(){
        return !CommonConstant.STATUS_PASSWORD_EXPIRE.equals(isEnabled) ? true : false;
    }

    public boolean isDisabled() {
        return !CommonConstant.STATUS_NORMAL.equals(isEnabled) ? true : false;
    }


}
